package com.cxq.finalproject.util;


import com.cxq.finalproject.R;

import java.lang.reflect.Field;

//通过文件名字找资源id
public class GetImgIDByName {
    private String name;
    public GetImgIDByName(String name){
        this.name = name;
    }

    public int getResId(){
        Class drawable = R.drawable.class;
        Field field;
        int r_id;
        try {
            field = drawable.getField(name);
            r_id = field.getInt(field.getName());
            return r_id;
        } catch (Exception e) {
//            r_id = R.drawable.user_default;
            return -1;
        }
    }
}
